import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from './views/Login.vue'
import Home from './views/Home.vue'
import Welcome from './components/Welcome.vue'
import Users from './components/user/Users.vue'
import Pets from './components/user/Pets.vue'
import Coms from './components/user/Coms.vue'
import Spes from './components/user/Spes.vue'

Vue.use(VueRouter)

const router = new VueRouter({
  routes : [
    //重定向
    { path: "/", redirect: '/login' },
    //登录首页
    { path: '/login', component: Login },

    { 
      path: '/home', 
      component: Home, 
      redirect: '/Welcome',
      children :[
        {path: '/Welcome', component: Welcome},
        {path: '/users', component: Users},
        {path: '/pets', component: Pets},
        {path: '/coms', component: Coms},
        {path: '/spes', component: Spes}
    ]},
    
  ]
})

//挂载路由导航守卫
// router.beforeEach((to,from,next) => {
//   if(to.path == '/login') return next();
//   //获取token
//   const tokenStr = window.sessionStorage.getItem('token')
//   if (!tokenStr) return next('/login')
//   next()
// })

//next()表示放行【next('/login') 强制跳转】 to要访问的路径 from代表从哪个路径跳转而来

export default router
